//
//  EditProfileGenderViewController.swift
//  XGamesLive
//
//  Created by ios on 2024/5/16.
//

import UIKit

class EditProfileGenderViewController: UIViewController,CustomNavgationBar{
    
    var femaleItem: LoginGenderItemView!
    var maleItem: LoginGenderItemView!

    override func viewDidLoad() {
        super.viewDidLoad()
        self.createCustomBackgroundView()
        self.createXglView()
        self.creatClearNavigationBar(title: "Edit Profile")
        self.femaleItem.isSelected = true
        self.maleItem.isSelected = false
        LoginInfor.share.infor?.gender = 0
    }


}

extension EditProfileGenderViewController{
    @objc private func femaleAction(){
        self.femaleItem.isSelected = true
        self.maleItem.isSelected = false
        LoginInfor.share.infor?.gender = 0
    }
    
    @objc private func maleAction(){
        self.femaleItem.isSelected = false
        self.maleItem.isSelected = true
        LoginInfor.share.infor?.gender = 1
    }
    
    @objc private func returnAction(){
        self.navigationController?.popViewController()
    }
    
    @objc private func nextAction(){
        let vc = EditProfileGamesViewController()
        self.navigationController?.pushViewController(vc)
    }
    
    @objc private func skipAction(){
        let vc = EditProfileGamesViewController()
        self.navigationController?.pushViewController(vc)
    }
}

extension EditProfileGenderViewController{
    
    private func createXglView(){
        let titleText = UILabel().then { make in
            make.text = "Gender"
            make.textColor = .white
            make.font = UIFont.pingfangSC_Semibold(fontSize: 34.0)
        }
        self.femaleItem = LoginGenderItemView(title: "Female", normalImage: "icon_female_normal", selectImage: "icon_female_selected").then({ make in
            make.itemButton.addTarget(self, action: #selector(self.femaleAction), for: .touchUpInside)
        })
        self.maleItem = LoginGenderItemView(title: "Male", normalImage: "icon_male_normal", selectImage: "icon_male_selected").then({ make in
            make.itemButton.addTarget(self, action: #selector(self.maleAction), for: .touchUpInside)
        })
       
        let returnButton = UIButton().then { make in
            make.setTitle("Return", for: .normal)
            make.setTitleColor(UIColor.hexColor("#80FFE6"), for: .normal)
            make.titleLabel?.font = UIFont.pingfangSC_Regular(fontSize: 18.0)
            make.backgroundColor = UIColor.hexColor("#80FFE6").withAlphaComponent(0.1)
            make.layerCornerRadius = 20.0
            make.addTarget(self, action: #selector(self.returnAction), for: .touchUpInside)
        }
        let nextButton = UIButton().then { make in
            make.setTitle("Next", for: .normal)
            make.setTitleColor(UIColor.hexColor("#191A1D"), for: .normal)
            make.titleLabel?.font = UIFont.pingfangSC_Regular(fontSize: 18.0)
            make.backgroundColor = UIColor.hexColor("#80FFE6")
            make.layerCornerRadius = 20.0
            make.addTarget(self, action: #selector(self.nextAction), for: .touchUpInside)
        }
        self.view.addSubviews([titleText,femaleItem,maleItem,returnButton,nextButton])
        
        titleText.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(conversionWithScrennWidth(value: 188.0))
        }
        femaleItem.snp.makeConstraints { make in
            make.top.equalTo(titleText.snp.bottom).offset(conversionWithScrennWidth(value: 74.0))
            make.right.equalTo(self.view.snp.centerX).offset(-conversionWithScrennWidth(value: 32.0))
//            make.width.equalTo(conversionWithScrennWidth(value: 120.0))
            make.height.equalTo(conversionWithScrennWidth(value: 180.0))
        }
        maleItem.snp.makeConstraints { make in
            make.centerY.height.width.equalTo(femaleItem)
            make.left.equalTo(femaleItem.snp.right).offset(conversionWithScrennWidth(value: 64.0))
        }
        nextButton.snp.makeConstraints { make in
            make.left.equalTo(self.view.snp.centerX).offset(conversionWithScrennWidth(value: 5.0))
            make.width.equalTo(conversionWithScrennWidth(value: 168.0))
            make.height.equalTo(48.0)
            make.bottom.equalTo(-BottomHeight-48.0)
        }
        returnButton.snp.makeConstraints { make in
            make.centerY.height.width.equalTo(nextButton)
            make.right.equalTo(nextButton.snp.left).offset(-10.0)
        }
    }
    
    func creatClearNavigationBar(title: String) {
        self.navigationController?.navigationBar.barStyle = .default
        setNeedsStatusBarAppearanceUpdate()
        let backColor = UIColor.clear
        let imageIcon = imageWithName("icon_xgl_back_white")
       
        let naviView = UIView().then { make in
            make.backgroundColor = backColor
        }
        let backItem = MXCustomButton().then { make in
            make.setImage(imageIcon, for: .normal)
            make.buttonSelectAction { [weak self] in
                guard let `self` = self else { return }
                self.backAction()
            }
        }
        let titleView = UILabel().then { make in
            make.textColor = UIColor.white
            make.font = UIFont.pingfangSC_Regular(fontSize: 18.0)
            make.text = title
        }
        let skipItem = UIButton().then { make in
            make.addTarget(self, action: #selector(self.skipAction), for: .touchUpInside)
            make.setTitle("Skip", for: .normal)
            make.setTitleColor(UIColor.hexColor("#80FFE6"), for: .normal)
            make.titleLabel?.font = UIFont.pingfangSC_Regular(fontSize: 14.0)
            make.backgroundColor = UIColor.hexColor("#001310")
            make.layerCornerRadius = 12.0
        }
        naviView.addSubview(backItem)
        naviView.addSubview(titleView)
        naviView.addSubview(skipItem)
        self.view.addSubview(naviView)
        backItem.snp.makeConstraints { make in
            make.left.equalTo(5.0)
            make.width.height.equalTo(50.0)
            make.bottom.equalTo(-3.0)
        }
        titleView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.centerY.equalTo(backItem)
        }
        skipItem.snp.makeConstraints { make in
            make.centerY.equalTo(titleView)
            make.right.equalTo(-16.0)
            make.width.equalTo(conversionWithScrennWidth(value: 48.0))
            make.height.equalTo(24.0)
        }
        naviView.snp.makeConstraints { make in
            make.centerX.top.equalToSuperview()
            make.width.equalTo(ScreenWidth)
            make.height.equalTo(PanNavibarH)
        }
    }
}
